
local attrs = {'攻击','生命','三维','护甲','回血','伤害'}
local register_data = function(hard)
    local key = ('难%s'):format(hard)
    local atk = load_excel('数值投放.xlsx','英雄攻击')
    local smz = load_excel('数值投放.xlsx','英雄生命')
    local sxz = load_excel('数值投放.xlsx','英雄三维')
    local def = load_excel('数值投放.xlsx','英雄护甲')
    local hxz = load_excel('数值投放.xlsx','英雄回血')
    local dmg = load_excel('数值投放.xlsx','英雄伤害')
    local enemy_def = load_excel('数值投放.xlsx','怪物护甲')
    local info1 = {}
    local info2 = {}
    for a=1,16 do
        info1[a] = {
            ['攻击'] = atk[a][key],
            ['生命'] = smz[a][key],
            ['三维'] = sxz[a][key],
            ['护甲'] = def[a][key],
            ['回血'] = hxz[a][key],
            ['伤害'] = dmg[a][key],
            ['怪物护甲'] = enemy_def[a][key],
        }
    end


    for b=1,#info1 do
        local data1 = info1[b-1] or {}
        local data2 = info1[b]
        for a=1,100 do
            local new = {}
            for _,name in ipairs(attrs) do
                new[name] = (data1[name] or data2[name]/2) + (data2[name] - (data1[name] or data2[name]/2))*a*0.01
            end
            new['怪物护甲'] = data2['怪物护甲']
            info2[#info2 + 1] = new
        end
    end
    return info2
end
data_list = register_data(1)



ac.game:event '游戏-设置难度'(function(_,hard)
    data_list = register_data(hard)
end)

local unit_data = load_excel('数值投放.xlsx','怪物参数')
function ac.unit.__index:set_enemy_level(level,name,ex)
    local ex = ex or 100
    local level = math.floor(level*100 - 100 + ex)
    local data1 = unit_data[name or self.name]
    local data2 = data_list[level]
    if not data1 then
        log.error('错误怪物类型',self)
        return
    end
    if not data2 then
        log.error('错误怪物等级',level)
        return
    end
    local qsx = data2['三维'] or 0
    local time = data1['击杀时间'] or 20
    local rate = data1['每秒输出'] or 1
    local atk = data2['攻击']
    local smz = data2['生命']
    local dmg = data2['伤害']
    local def = data2['护甲'] or 0
    local hxsd = (data2['回血'] or 0)
    if data1['移速'] then
        self:set('移动速度',data1['移速'] or 0)
    end
    local udef = (data1['基础护甲'] or 0) + (data2['怪物护甲'] or 0)
    self:set('攻击速度',(data1['攻击速度'] or 0) + 100)
    self:set('基础护甲',udef)
    self:set('基础魔抗',(data1['基础魔抗'] or 0) + (data2['怪物护甲'] or 0))

    local dps = 0
    if rate>0 then
        dps = smz*rate/100 + hxsd
    else
        dps = -hxsd*rate/100
    end
    
    
    self:set('基础攻击',dps * (1 + def*0.01))
    self:set('生命上限',atk*time* (1 + 0.001*qsx)*(1 + dmg*0.01)/(1 + 0.01*udef))
    if self:is_type('精英') then
        unit_add_life3(self)
    elseif self:is_type('Boss') then
        unit_add_life4(self)
    elseif self:is_type('挑战') then
        unit_add_life2(self)
    elseif self.owner.id>5 and self.owner.id<=12 then
        self.ui_title = ''
        unit_add_life2(self)
    end
    --self:set('单位体积',)
end
